package com.gopay.common.user.mcc.manager.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gopay.common.domain.user.mcc.UserMccTransformReq;
import com.gopay.common.domain.user.mcc.UserMccTransformRes;
import com.gopay.common.order.dao.CommonQueryDAO;
import com.gopay.common.user.mcc.manager.UserMccTransformManager;

@Service(value = "userMccTransformManager")
public class UserMccTransformManagerImpl implements UserMccTransformManager {

	@Resource(name = "commonQueryDAO")
	private CommonQueryDAO commonQueryDAO;

	@Override
	public UserMccTransformRes graspUserMccInfo(UserMccTransformReq req) {
		UserMccTransformRes res = new UserMccTransformRes();
		StringBuilder sb = new StringBuilder();

		sb.append(" select c.gopay_mcc_province, c.gopay_mcc_num, b.bank_mcc_code, c.corp_name, b.bank_mcc_code_desc,c.gopay_mcc_code ");
		sb.append(" from cust_corp_info c ");
		sb.append(" left join DIC_GOPAY_BANK_MCC b on c.gopay_mcc_code = b.gopay_mcc_code ");
		sb.append(" where c.cust_id = :custId ");
		sb.append(" and b.bank_code = :bankCode ");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("custId", req.getCustId());
		map.put("bankCode", req.getBankCode());
		List<Object[]> rsList = commonQueryDAO.findBySql(sb.toString(), map);
		if (rsList != null && rsList.size() > 0) {
			Object[] arr = rsList.get(0);
			res.setProvince((String) arr[0]);
			res.setGopayMccNum((String) arr[1]);
			res.setBankMccCode((String) arr[2]);
			res.setCorpName((String) arr[3]);
			res.setBankMccDesc((String) arr[4]);
			res.setGopayMccCode((String) arr[5]);
			return res;
		} else {
			return null;
		}
	}
	@Override
    public UserMccTransformRes graspUserInfo(UserMccTransformReq req) {
		UserMccTransformRes res = new UserMccTransformRes();
		StringBuilder sb = new StringBuilder();

		sb.append(" select c.gopay_mcc_province, c.gopay_mcc_num,  c.corp_name, c.gopay_mcc_code ");
		sb.append(" from cust_corp_info c ");
		sb.append(" where c.cust_id = :custId ");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("custId", req.getCustId());
		List<Object[]> rsList = commonQueryDAO.findBySql(sb.toString(), map);
		if (rsList != null && rsList.size() > 0) {
			Object[] arr = rsList.get(0);
			res.setProvince((String) arr[0]);
			res.setGopayMccNum((String) arr[1]);
			res.setCorpName((String) arr[2]);
			res.setGopayMccCode((String) arr[3]);
			return res;
		} else {
			return null;
		}
	}
}
